<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\controller;

use app\common\model\ArticleCategory;
use app\common\model\Category;
use app\common\model\VideoCate;

/**
 * 文章控制器
 */
class Article extends AdminBase
{

    /**
     * 快讯文章列表
     */
    public function articleList()
    {

        $where = $this->logicArticle->getWhere($this->param);
        $where['category_id']=1;
        $this->assign('list', $this->logicArticle->getArticleList($where, 'a.*,m.nickname,c.name as category_name', 'a.create_time desc'));
        $this->assign('type',1);
        return $this->fetch('article_list');
    }



    /**
     * 文章添加
     */
    public function articleAdd()
    {

        $this->articleCommon();
        if(empty($this->param['type'])){
            $this->param['type']=1;
            $type=1;
        }else{
            $type=$this->param['type'];
        }
        $this->assign('tag',ArticleCategory::all(['status'=>1,'type'=>2]));
        $this->assign('type', $type);
        return $this->fetch('article_edit');
    }

    /**
     * 文章编辑
     */
    public function articleEdit()
    {

        $this->articleCommon();

        $info = $this->logicArticle->getArticleInfo(['a.id' => $this->param['id']], 'a.*,m.nickname,c.name as category_name');

        !empty($info) && $info['img_ids_array'] = str2arr($info['img_ids']);
        $this->assign('tag',ArticleCategory::all(['status'=>1,'type'=>2]));
        $this->assign('type', $info['category_id']);
        $this->assign('info', $info);

        return $this->fetch('article_edit');
    }


    /**
     * 文章列表
     */
    public function articleList1()
    {

        $where = $this->logicArticle->getWhere($this->param);
        $where['category_id']=2;
        $this->assign('list', $this->logicArticle->getArticleList($where, 'a.*,m.nickname,c.name as category_name', 'a.create_time desc'));
        $this->assign('type',2);
        return $this->fetch('article_list');
    }


    /**
     * 文章列表
     */
    public function articleList2()
    {

        $where = $this->logicArticle->getWhere($this->param);
        $where['category_id']=3;
        $this->assign('list', $this->logicArticle->getArticleList($where, 'a.*,m.nickname,c.name as category_name', 'a.create_time desc'));
        $this->assign('tag',ArticleCategory::all(['status'=>1,'type'=>2]));

        $this->assign('type',3);
        return $this->fetch('article_list');
    }



    /**
     * 文章添加与编辑通用方法
     */
    public function articleCommon()
    {

        IS_POST && $this->jump($this->logicArticle->articleEdit($_POST));



        $this->assign('param',  $this->param);
        $cate=$this->logicArticle->getArticleCategoryList(['type'=>$this->param['type']], 'id,name', '', false);
        $this->assign('video_cate',VideoCate::all(['status'=>1]));
        $this->assign('article_category_list', $cate['list']);
    }

    /**
     * 文章分类添加
     */
    public function articleCategoryAdd()
    {

        IS_POST && $this->jump($this->logicArticle->articleCategoryEdit($this->param));
        $this->assign('type',$this->param['type']);
        return $this->fetch('article_category_edit');
    }

    /**
     * 文章分类编辑
     */
    public function articleCategoryEdit()
    {

        IS_POST && $this->jump($this->logicArticle->articleCategoryEdit($this->param));

        $info = $this->logicArticle->getArticleCategoryInfo(['id' => $this->param['id']]);
        $this->assign('type',$info['type']);
        $this->assign('info', $info);

        return $this->fetch('article_category_edit');
    }

    /**
     * 文章分类列表
     */
    public function articleCategoryList()
    {
       $where['type']=1;
        $this->assign('list', $this->logicArticle->getArticleCategoryList( $where));
        $this->assign('type',1);
        return $this->fetch('article_category_list');
    }

    /**
     * 文章标签列表
     */
    public function articleCategoryList1()
    {
        $where['type']=2;
        $this->assign('list', $this->logicArticle->getArticleCategoryList($where));
        $this->assign('type',2);
        return $this->fetch('article_category_list');
    }

    /**
     * 文章分类删除
     */
    public function articleCategoryDel($id = 0)
    {

        $this->jump($this->logicArticle->articleCategoryDel(['id' => $id]));
    }

    /**
     * 数据状态设置
     */
    public function setStatus()
    {

        $this->jump($this->logicAdminBase->setStatus('Article', $this->param));
    }


    /**
     * 数据状态设置
     */
    public function update_info()
    {

        $this->jump($this->logicArticle->update_info($this->param));
    }


    /**
     * 视频分类添加
     */
    public function videoCategoryAdd()
    {

        IS_POST && $this->jump($this->logicArticle->videoCategoryEdit($this->param));
        return $this->fetch('video_category_edit');
    }

    /**
     * 视频分类编辑
     */
    public function videoCategoryEdit()
    {

        IS_POST && $this->jump($this->logicArticle->articleCategoryEdit($this->param));

        $info = $this->logicArticle->getVideoCategoryInfo(['id' => $this->param['id']]);

        $this->assign('info', $info);

        return $this->fetch('video_category_edit');
    }

    /**
     * 视频分类列表
     */
    public function videoCategoryList()
    {

        $this->assign('list', $this->logicArticle->getVideoCategoryList());

        return $this->fetch('video_category_list');
    }


    /**
     * 视频分类删除
     */
    public function videoCategoryDel($id = 0)
    {

        $this->jump($this->logicArticle->VideoCategoryDel(['id' => $id]));
    }




}
